﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace UbbTimetable2
{
    /// <summary>
    /// A DAO that handles all data related to groups.
    /// </summary>
    class GroupDao : Dao
    {
        private String err = "";

        /// <summary>
        /// The last error message.
        /// </summary>
        public String Err
        {
            get { return err; }
        }

        /// <summary>
        /// Returns the list of groups.
        /// </summary>
        /// <returns>The list of groups.</returns>
        public List<String> GetGroupList()
        {
            String query = "SELECT DISTINCT Csoport FROM Alcsoport";
            SqlDataReader rdr = ExecuteReader(query, ref err);

            List<String> list = new List<String>();
            if (err == "OK")
            {
                while (rdr.Read())
                {
                    String item;
                    item = rdr[0].ToString().TrimEnd();

                    list.Add(item);
                }
            }
            CloseDataReader(rdr);
            return list;
        }
    }
}
